import type { UniFormsRules } from '@uni-helper/uni-ui-types'

/**
 * 项目表单规则
 * @author lian
 */
export const ProjectFormRules: UniFormsRules = {
  projectName: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 20,
        errorMessage: NAME_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('不能小于五个字符')
          }
          return true
        },
      },
    ],
  },
  brief: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 50,
        errorMessage: BRIEF_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 20) {
            callback('不能小于20个字符')
          }
          return true
        },
      },
    ],
  },
  implementationPlan: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 200,
        errorMessage: NAME_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('不能小于50个字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  projectDescHtml: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 2000,
        errorMessage: BRIEF_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('不能小于50个字符')
          }
          return true
        },
      },
    ],
  },
  status: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  targetAmount: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        format: 'number',
        errorMessage: REQUIRED_NUMBER,
      },
      {
        minimum: 1000,
        maximum: 10000000,
        errorMessage: AMOUNT_RANGE,
      },
    ],
  },
}

/**
 * 活动表单规则
 * @author lian
 */
export const ActivityFormRules: UniFormsRules = {
  activityName: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 20,
        errorMessage: NAME_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('不能小于5个字符')
          }
          return true
        },
      },
    ],
  },
  brief: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 50,
        errorMessage: BRIEF_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 20) {
            callback('不能小于20个字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  startTimeAndEndTime: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  address: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  requireVolunteers: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        format: 'number',
        errorMessage: REQUIRED_NUMBER,
      },
      {
        minimum: 5,
        maximum: 100,
        errorMessage: PEOPLE_RANGE,
      },
    ],
  },
  status: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
  activityDescHtml: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 2000,
        errorMessage: DESC_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('不能小于50个字符')
          }
          return true
        },
      },
    ],
  },
}

/**
 * 动态表单规则
 * @author lian
 */
export const DynamicFormRules: UniFormsRules = {
  title: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 20,
        errorMessage: NAME_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('不能小于五个字符')
          }
          return true
        },
      },
    ],
  },
  content: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
      {
        maxLength: 200,
        errorMessage: NAME_MAX_LENGTH,
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 15) {
            callback('不能小于15字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: REQUIRED,
      },
    ],
  },
}
